package com.yang.jdbc01;

import java.sql.*;

/**
 * @author yangjiming
 * @create 2021-03-26 20:26
 */
public class SelectMysql02 {
    public static void main(String[] args) throws Exception{
        Class.forName("com.mysql.jdbc.Driver");

        String url="jdbc:mysql://master:3306/shujia";
        String username="root";
        String password="123456";
        Connection conn = DriverManager.getConnection(url, username, password);

        String sql="select * from student where age=? and name=?";

        PreparedStatement ps = conn.prepareStatement(sql);

        ps.setString(1,"18");
        ps.setString(2,"test");


        ResultSet rs = ps.executeQuery();

        while(rs.next()){
            String name=rs.getString("name");
            System.out.println(name);
        }

        rs.close();
        ps.close();
        conn.close();
    }
}
